/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.VipServiceGift;
import com.sasis.dao.VipServiceGiftDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class VipServiceGiftDaoiBatis extends BaseDaoiBATIS implements VipServiceGiftDao {

    /**
     * @see com.sasis.dao.VipServiceGiftDao#getVipServiceGifts(com.sasis.model.VipServiceGift)
     */
    public List getVipServiceGifts(final VipServiceGift vipServiceGift) {
          return getSqlMapClientTemplate().queryForList("getVipServiceGifts", vipServiceGift);
    }

    /**
     * @see com.sasis.dao.VipServiceGiftDao#getVipServiceGift(Integer id)
     */
    public VipServiceGift getVipServiceGift(Integer id) {
        VipServiceGift vipServiceGift = (VipServiceGift) getSqlMapClientTemplate().queryForObject("getVipServiceGift", id);

//        if (vipServiceGift == null) {
//            throw new ObjectRetrievalFailureException(VipServiceGift.class, id);
//        }

        return vipServiceGift;
    }

    /**
     * @see com.sasis.dao.VipServiceGiftDao#saveVipServiceGift(VipServiceGift vipServiceGift)
     */    
    public int saveVipServiceGift(final VipServiceGift vipServiceGift) {
        Integer id = vipServiceGift.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addVipServiceGift", vipServiceGift);
        } else {
            getSqlMapClientTemplate().update("updateVipServiceGift", vipServiceGift);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(VipServiceGift.class, id);
        }
        return id.intValue();
    }

    /**
     * @see com.sasis.dao.VipServiceGiftDao#removeVipServiceGift(Integer id)
     */
    public void removeVipServiceGift(VipServiceGift vipServiceGift) {
        getSqlMapClientTemplate().update("deleteVipServiceGift",  vipServiceGift);
    }
}
